#region System
using System;
using System.Collections.Generic;
using System.IO;
using CF.Framework.Engine.Drawing;
using CF.Framework.Engine.Misc;
using CF.Framework.Engine.Screens;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#endregion

namespace CF.Framework.Engine.Effects
{
	public class FlashEffect : Effect
	{
		private TimeSpan drawTime;
		private bool drawFlag;
		private TimeSpan loopTime;

		public TimeSpan Interval  { get; set; }
		public TimeSpan Duration { get; set; }

		public FlashEffect()
		{
			this.Interval = TimeSpan.FromMilliseconds(200);
			this.Duration = TimeSpan.FromMilliseconds(1000);

			this.drawTime = TimeSpan.Zero;
			this.drawFlag = true;
		}

		public override void OnStart()
		{
			this.drawTime = TimeSpan.Zero;
			this.drawFlag = true;
			this.loopTime = TimeSpan.Zero;

			this.IsDoing = true;
			this.IsRunning = true;
		}

		public override void OnStop()
		{
		}

		public override void OnUpdate(GameTime gameTime)
		{
			if (this.IsDoing)
			{
				this.loopTime += gameTime.ElapsedGameTime;
			}

			if (this.loopTime > this.Duration
				&& this.Duration > TimeSpan.Zero)
			{
				Target.Visibility = Controls.Visibility.Visible;

				this.IsCompleted = true;
				this.IsDoing = false;
				this.IsRunning = false;
			}
			else if (this.IsDoing
				|| Duration == TimeSpan.Zero)
			{
				this.drawTime += gameTime.ElapsedGameTime;

				if (this.drawTime >= this.Interval)
				{
					this.drawTime -= this.Interval;
					this.drawFlag = !drawFlag;
				}

				Target.Visibility = drawFlag ? Controls.Visibility.Visible : Controls.Visibility.Collapsed;
			}
		}

		public override void Dispose()
		{
		}
	}
}
